package Zinfo;
$Mojo::Webqq::Plugin::Pu::PRIORITY = 1;
use Mojo::Zabbix::Hostinfo;
use Encode;


my $re=qr([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]);
my $ipre=qr/($re\.){3}$re$/;

    
sub call {
    my $client = shift;
    $client->on(receive_message=>sub{
        my($client,$msg)=@_;
        return if not $msg->allow_plugin;
        return if $msg->content !~ /ZabbixHinfo\s*($ipre)/;
        my $arg= $1 if $msg->content=~ /ZabbxHinfo\s*($ipre)/;
        $reply= Encode::encode("utf8",hostinfo($arg));
        $client->reply_message($msg,$reply,sub{$_[1]->msg_from("bot")}) if $reply;
    });
}
1;
